package com.nlecloud.bc.config;

import lombok.extern.slf4j.Slf4j;
import org.fisco.bcos.sdk.BcosSDK;
import org.fisco.bcos.sdk.client.Client;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author warrior
 * @description fisco bcos 配置
 */
@Configuration
@Slf4j
public class FiscoBcosConfig {

    @Value("${fisco.bcos.account.path}")
    private String accountPath;

    @Bean
    public Client client(){
        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:fisco-config.xml");
        BcosSDK bcosSDK = context.getBean(BcosSDK.class);
        // 初始化可向群组1发交易的Client
        Client client = bcosSDK.getClient(Integer.valueOf(1));
        //加载账户
        client.getCryptoSuite().loadAccount("pem",accountPath,"null");
        return client;
    }
}
